package com.ruoyi.service.impl;

import java.util.*;

import com.ruoyi.common.result.Result;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.domain.*;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.mapper.T05Mapper;
import com.ruoyi.mapper.T06Mapper;
import com.ruoyi.mapper.T09Mapper;
import com.ruoyi.service.IT03Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.T07Mapper;
import com.ruoyi.service.IT07Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 个人历史记录Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-30
 */
@Service
public class T07ServiceImpl implements IT07Service
{
    @Autowired
    private T07Mapper t07Mapper;
    @Autowired
    private T06Mapper T06Mapper;
    @Autowired
    private T10ServiceImpl t10ServiceImpl;
    @Autowired
    private T18ServiceImpl t18ServiceImpl;

    @Autowired
    private TokenService tokenService;
    @Autowired
    private T09Mapper t09Mapper;
    @Autowired
    private T05Mapper t05Mapper;
    @Autowired
    private T06Mapper t06Mapper;
    @Autowired
    private IT03Service t03Service;

    /**
     * 查询个人历史记录
     *
     * @param F0701 个人历史记录主键
     * @return 个人历史记录
     */
    @Override
    public T07 selectT07ByF0701(Long F0701)
    {
        return t07Mapper.selectT07ByF0701(F0701);
    }

    /**
     * 查询个人历史记录列表
     *
     * @param t07 个人历史记录
     * @return 个人历史记录
     */
    @Override
    public List<T07> selectT07List(T07 t07)
    {
        PageUtils.startPage();
        return t07Mapper.selectT07List(t07);
    }

    /**
     * 新增个人历史记录
     *
     * @param t07 个人历史记录
     * @return 结果
     */
    @Override
    public int insertT07(T07 t07)
    {
        return t07Mapper.insertT07(t07);
    }

    /**
     * 修改个人历史记录
     *
     * @param t07 个人历史记录
     * @return 结果
     */
    @Override
    public int updateT07(T07 t07)
    {
        return t07Mapper.updateT07(t07);
    }

    /**
     * 批量删除个人历史记录
     *
     * @param F0701s 需要删除的个人历史记录主键
     * @return 结果
     */
    @Override
    public int deleteT07ByF0701s(Long[] F0701s)
    {
        return t07Mapper.deleteT07ByF0701s(F0701s);
    }

    /**
     * 删除个人历史记录信息
     *
     * @param F0701 个人历史记录主键
     * @return 结果
     */
    @Override
    public int deleteT07ByF0701(Long F0701)
    {
        return t07Mapper.deleteT07ByF0701(F0701);
    }

    @Override
    public TodaySum counttoken(Long userId) {
        T06 t06 = T06Mapper.getT06ByF0601(userId);
        TodaySum todaySum = t07Mapper.counttoken(userId);
        Long count= t07Mapper.counts(userId);
        //总token
        todaySum.setCounttoken(count);
        return todaySum;
    }

    @Override
    public List<T07> selectlist(Long userId) {
        return t07Mapper.selectlist(userId);
    }

    @Override
    public Integer todayMoney() {
        return t07Mapper.todayMoney();
    }

    @Override
    public int increase() {
        return t07Mapper.increase();
    }

    @Override
    public int total() {
        return t07Mapper.total();
    }

    @Override
    public List<T11> selectlisttoday() {
        return t07Mapper.selectlisttoday();
    }

    @Override
    public List<T11> selectlisttotal() {
        return t07Mapper.selectlisttotal();
    }

    @Override
    public List<QUTH> selectlistWeek(Long comId) {
        return t07Mapper.selectlistWeek(comId);
    }

    @Override
    public List<T07> GetComSelect(Long comId) {
        return t07Mapper.GetComSelect(comId);
    }

    @Override
    public List<T11> selectYesterDay() {
        return t07Mapper.selectYesterDay();
    }

    @Override
    public List<T04> selectAllBefore() {
        return t07Mapper.selectAllBefore();
    }

    public Result getComweekData() {
        List<Map<String, Objects>> week = t07Mapper.getComweekData();
        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> totalCompany = t07Mapper.getTotalCompany();
        map.put("week",week);
        map.put("totalCompany",totalCompany);

        Long totalMoney = t10ServiceImpl.getTotalMoney();

        map.put("totalMoney",totalMoney);


        return Result.success(map,"查询成功");
    }

    @Override
    public Result getTotalCompany(HttpServletRequest request) {
        Long userId=tokenService.getLoginUser(request).getUser().getUserId();
        Long CompId = t18ServiceImpl.selectF0301ByF1801(userId);
        List<Map<String,Object>> totalCompany = t07Mapper.ComWeekData(CompId);
        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> huoyue = t07Mapper.getHuoyue(CompId);
        map.put("totalCompany",totalCompany);
        //查询最活跃的两个用户
        map.put("huoyue",huoyue);
        Long countKnowlwdge = t09Mapper.countKnowlwdge(CompId);
        //查询总的知识库数量
        map.put("countKnowlwdge",countKnowlwdge);
        Long countPerson = t06Mapper.countPerson(CompId);
        Long countDept = t05Mapper.countDept(CompId);
        //查询总人数
        map.put("countPerson",countPerson);
        //查询总部门数量
        map.put("countDept",countDept);
        T03 t03 = t03Service.selectT03ByF0301(CompId);
        //查询总token
        map.put("countToken",t03.getF0310());

        Long countCompany = t10ServiceImpl.getComTotal(CompId);

        map.put("countCompany",countCompany);
        return Result.success(map,"查询成功");
    }

    @Override
    public List<T07> selectT07ListNoPage(T07 t07) {
        return t07Mapper.selectT07List(t07);
    }
}
